<?php

namespace App\Containers\AppSection\Questionnaire\UI\API\Transformers;

use App\Containers\AppSection\Questionnaire\Models\Response;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;

class ResponseTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'form', 'values'
    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [

    ];

    public function transform(Response $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'persons' => (int)$t->values()->max('person')
        ];
    }

    public function includeForm(Response $t): Item
    {
        return $this->item($t->form, new FormTransformer);
    }

    public function includeValues(Response $t): Collection
    {
        return $this->collection($t->values, new ValueTransformer);
    }
}
